﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sekretar.DataLayer;

namespace Sekretar.Repository
{
    public class RRadnoMesto : BaseRepository, InterfaceRepository<DataLayer.RadnoMesto>
    {
        public IQueryable<DataLayer.RadnoMesto> VratiSve()
        {
            dc = new DataLayer.SekretarDataContext();
            return dc.RadnoMestos;
        }

        public DataLayer.RadnoMesto Nov()
        {
            this.jeNov = true;

            RadnoMesto n = new RadnoMesto();
            n.Status = true;
            n.KorisnikId = Common.Properties.Settings.Default.KorisnikId;
            n.DatumRada = Common.Tools.SqlFunkcije.VratiTrenutnoVreme();

            return n;
        }

        public DataLayer.RadnoMesto Izmeni(int id)
        {
            return dc.RadnoMestos.SingleOrDefault(c => c.RadnoMestoId == id);
        }

        public int Snimi(DataLayer.RadnoMesto t)
        {
            if (this.jeNov) dc.RadnoMestos.InsertOnSubmit(t);
            dc.SubmitChanges();
            return t.RadnoMestoId;
        }

        public void Brisi(int id)
        {
            dc.RadnoMestos.DeleteOnSubmit(dc.RadnoMestos.SingleOrDefault(c => c.RadnoMestoId == id));
            dc.SubmitChanges();
        }

        public IQueryable<DataLayer.RadnoMesto> VratiSveAktivne()
        {
            dc = new DataLayer.SekretarDataContext();
            return dc.RadnoMestos.Where(c => c.Status == true);
        }
    }
}
